﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using CP.Entities;
using CP.Repositories.GPM;
using CP.Utility;

namespace CP.Controllers.GPM
{
    public class UserGroupController
    {
        public IList<User_Group> GetAllUserGroups()
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetAllUserGroups();
        }

        public User_Group GetGroupByID(int groupid)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetGroupByID(groupid);
        }

        public IList<User_Group> GetGroupByMenuID(int menuid)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetGroupByMenuID(menuid);
        }

        public IList<User_Group> GetUnAuthGroupByMenuID(int menuid)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetUnAuthGroupByMenuID(menuid);
        }

        public IList<User_Group> GetGroupByButtonID(int webpartid, int buttonid)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetGroupByButtonID(webpartid, buttonid);
        }

        public IList<User_Group> GetUnAuthGroupByButtonID(int webpartid, int buttonid)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetUnAuthGroupByButtonID(webpartid, buttonid);
        }

        public IList<User_Group> GetGroupByUserID(string userid)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.GetGroupByUserID(userid);
        }

        public IList<User_Group_Relation> GetUserRelations(string userid)
        {
            UserInfoRepository rep = new UserInfoRepository();
            return rep.GetUserRoleRelations(userid);
        }

        public IList<User_Group_Relation> GetUserRelsByGroupID(int groupid)
        {
            UserInfoRepository rep = new UserInfoRepository();
            return rep.GetUserRoleRelations(groupid);
        }

        public bool SetUserRole(string userid, int defaultRole, IList<int> groupids)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.InsertUserRole(userid, defaultRole, groupids);
        }

        public bool DeleteUserGroups(IList<int> groupids)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.DeleteGroups(groupids);
        }

        public bool AddUserGroup(User_Group group)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.AddUserGroup(group);
        }

        public bool EditUserGroup(User_Group group)
        {
            UserGroupRepository rep = new UserGroupRepository();
            return rep.UpdateUserGroup(group);
        }
    }
}
